# coding=utf-8
import threading

from ..common.__const__ import ACTION_FAIL, ACTION_PASS, SUCCESS
from ..common.__script_config__ import script_config
from ..report.log import logger


mutex = threading.Lock()

def set_fail(str_err_msg):
    '''
    设置结果失败

    :Args:
     - str_err_msg: 失败原因

    :Example:
     - 例: set_fail('登录失败')
    '''
    if mutex.acquire():
        try:
            script_config.return_flag = ACTION_FAIL
            script_config.return_value = str_err_msg
        finally:
            mutex.release()
    logger.debug('set fail:' + str(str_err_msg))

def set_pass(str_pass_msg = SUCCESS):
    '''
    设置结果成功

    :Args:
     - str_pass_msg: 运行成功

    :Example:
     - 例: set_pass('登录成功')
    '''
    if mutex.acquire():
        try:
            script_config.return_flag = ACTION_PASS
            script_config.return_value = str_pass_msg
        finally:
            mutex.release()
    logger.debug('set success:' + str(str_pass_msg))

